﻿/*== TSL_prc_Summary_TestResults =========================================================================
Name			Qty		Min		Avg		Max		StdDev	90%		95%		ScenarioName	TestNameWithId
Immunization	45024	8.01	13.20	116.51	2.82	14.78	15.50	Scenario1		Immunization(000)
===============================================================================*/

/*== TSL_prc_Summary_TransactionResults ==================================================================
Id	Name								Qty		Min		Avg		Max		StdDev	90%		95%		ScenarioName	TestCaseName	TransactionNameWithId
38	Immunization.Immunization_CheckIn	45022	0.65	3.48	60.31	1.94	4.89	5.29	Scenario1		Immunization	Immunization.Immunization_CheckIn(038)
===============================================================================*/

/*== TSL_prc_Summary_PageResults ==================================================================
Id	Name												Qty		Min		Avg		Max		StdDev	90%		95%
117	IOrderInsuranceService.GetInsuranceEligibility_1SL	45011	0.04	0.87	22.75	0.61	1.43	1.60
===============================================================================*/

/*== ************ =========================================================================
DECLARE @RunId INT = 1

SELECT 
	b.RequestUri
	,(CASE a.Outcome WHEN 0 THEN 'Passed' ELSE 'Failed' END) AS Outcome
	,COUNT(a.Outcome) AS Qty 
FROM [dbo].[LoadTestPageDetail] AS a
INNER JOIN [dbo].[WebLoadTestRequestMap] AS b
	ON a.LoadTestRunId = b.LoadTestRunId
	AND a.PageId = b.RequestId
WHERE a.LoadTestRunId = @RunId
GROUP BY b.RequestUri, a.Outcome
ORDER BY b.RequestUri ASC
*/

/*== ************ =========================================================================
DECLARE @RunId INT = 3
DECLARE @offset BIGINT
SELECT @offset = MIN(SampleTimeStamp) FROM LoadTestPerformanceCounterSample WHERE LoadTestRunId = @RunId AND TestRunIntervalId = 0

SELECT 
CAST((SampleTimeStamp - @offset) / 10000000 AS INT) AS [Page Time] 
,ComputedValue 
 FROM [dbo].[LoadTestPerformanceCounterSample]
WHERE LoadTestRunId = 3 AND InstanceId = 1032
*/


/*
--DECLARE @RunId INT = 3
--DECLARE @StartTime DATETIME
--SET @StartTime = (SELECT StartTime FROM LoadTestRun WHERE LoadTestRunId = @RunId)

WITH C1 AS
(
	SELECT 
		LoadTestRunId
		, IntervalEndTime
		, ComputedValue
		, CASE 
			WHEN ComputedValue <> coalesce(LAG(ComputedValue) OVER(ORDER BY IntervalEndTime ASC),-1) THEN 1 
			ELSE null END AS IsGroupStart
	FROM LoadTestComputedCounterSample
	WHERE 
		CounterName = 'User Load' 
		AND InstanceName = '_Total'
)
,
C2 AS
(
	SELECT 
		LoadTestRunId
		, IntervalEndTime
		, ComputedValue
		,  COUNT(IsGroupStart) OVER(ORDER BY IntervalEndTime ROWS UNBOUNDED PRECEDING) AS [Group]
	FROM C1
)

SELECT 
	LoadTestRunId
	, MIN(IntervalEndTime) AS [IntervalStart]
	, MAX(IntervalEndTime) AS [IntervalEnd]
	, MIN(ComputedValue) AS ComputedValue
	, Count(*) AS NumberOfPoints
FROM C2
GROUP BY LoadTestRunId, [Group]
having count(*) >= 10;

--LoadTestRunId	StartOffset	EndOffset	UserLoad	NumberOfDataPoints
--3				5			120			1			24
--3				125			240			3			24
--3				245			360			5			24
--20				330			600			40			55
--20				630			900			60			55
--20				930			1200		80			55
--20				1230		1500		100			55
*/



/*
DECLARE		@RunId  INT = 3
		,@StartOffset INT = 5
		,@EndOffset INT = 120
		,@NameFilter nvarchar(255) = '%'
		,@NumberOfRows INT = 25

	SELECT
		c.PageId
		,d.RequestUri
		,COUNT(DISTINCT (c.PageDetailId)) AS Qty
		--(CASE a.Outcome WHEN 0 THEN 'Passed' ELSE 'Failed' END) AS Outcome
		,CASE @StartOffset WHEN NULL THEN
			CAST((COUNT(DISTINCT (c.PageDetailId)))/b.RunDuration AS Decimal(15,2))
			ELSE (COUNT(DISTINCT (c.PageDetailId)))/(@EndOffset - @StartOffset) END 
		AS Throughput
		,CAST(MIN(c.ResponseTime) AS Decimal(15,2)) AS Minimum
		,CAST(AVG(c.ResponseTime) AS Decimal(15,2)) AS Average
		,CAST(MAX(c.ResponseTime) AS Decimal(15,2)) AS Maximum
		,CAST(STDEV(c.ResponseTime) AS Decimal(15,2)) AS StdDev
	FROM 
		dbo.LoadTestTestDetail AS a
	INNER JOIN 
		LoadTestRun AS b 
		ON a.LoadTestRunId = b.LoadTestRunId
		
	INNER JOIN dbo.LoadTestPageDetail AS c 
		ON a.LoadTestRunId = c.LoadTestRunId 
		AND a.TestDetailId = c.TestDetailId
		AND c.Outcome = 0

	INNER JOIN dbo.WebLoadTestRequestMap AS d
		ON a.LoadTestRunId = d.LoadTestRunId
		AND c.PageId = d.RequestId
	WHERE 
		a.LoadTestRunId = @RunId
		AND (@StartOffset IS NULL OR c.EndTime >= DATEADD(second, @StartOffset, b.StartTime))
		AND (@EndOffset IS NULL OR c.EndTime < DATEADD(second, @EndOffset, b.StartTime))
		AND d.RequestUri LIKE @NameFilter
		AND (c.Outcome = 0) 
		AND (a.InMeasurementInterval = 1) 
	GROUP BY d.RequestUri, c.PageId, b.RunDuration

*/

